
const db = require('../../db')

// 获取校园公告信息列表(无需登录)
exports.getSchArt = (req,res)=>{
    
    var str = "select * from scharticle where isdelete = 0  order by pubdata desc"
    db.query(str,(err,results)=>{
        if(err) return res.cc(err)
        res.send({
            status:0,
            message:"获取成功",
            data:results
        })
    })
  
}

// 查看校园公告详情(无需登录)
exports.getDetailSchArt = (req,res)=>{
    const id = req.query.id
    // console.log(req.query,id)
    var str = "select * from scharticle  where id = ? "
    db.query(str,id,(err,results)=>{
        if(err) return res.cc(err)
       
        var views = results[0].view+1
        
        str = "update scharticle set view = ? where id =?"
        // 每调用一次接口，访问量+1
        db.query(str,[views,id],(err,result)=>{
            if(err) return res.cc(err)
            if(result.affectedRows != 1) return res.cc("访客记录获取失败")
            res.send({
                status:0,
                data:results[0]
            })

        })
    })
    
}
